package com.cbd.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cbd.dao.LandladyDao;
import com.cbd.pojo.Landlady;
import com.cbd.pojo.RentInfo;
import com.cbd.pojo.User;
import com.cbd.service.LandladyService;
import com.cbd.service.PersonalcarportService;
import com.cbd.service.PurposeService;
import com.cbd.service.RecordService;
import com.cbd.service.RenterService;
@Service
public class LandladyServiceImpl implements LandladyService {
	@Resource(name="landladyDaoImpl")
	private LandladyDao ladyDao;
	@Resource(name="renterServiceImpl")
	private RenterService rs;
	@Resource(name="personalcarportServiceImpl")
	private PersonalcarportService pls;
	@Resource(name="purposeServiceImpl")
	private PurposeService ps;
	@Resource(name="recordServiceImpl")
	private RecordService rds;
	@Override
	public int login(User user) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int regist(Landlady landlady) {
		// TODO Auto-generated method stub
		landlady.setLadyTime(new Date());
		return ladyDao.regist(landlady);
	}

	@Override
	public Landlady findLandLayById(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Landlady> findAllNoPassLandLady() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int updateLandladyType(int id) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Landlady> findAllPortNoPassLandLady() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Landlady findLadyByCard(String card) {
		// TODO Auto-generated method stub
		return ladyDao.findLadyByCard(card);
	}

	@Override
	public void publishRentInfo(RentInfo info) {
		// TODO Auto-generated method stub
		ladyDao.publishRentInfo(info);
	}

	@Override
	public int updateLandlady(Landlady landLady, int id) {
		// TODO Auto-generated method stub
		
		return ladyDao.updateLandlady(landLady, id);
	}

	@Override
	public Landlady showlandLady(int id) {
		// TODO Auto-generated method stub
		return ladyDao.showlandLady(id);
	}

	@Override
	public void agreeRentCarPort(int carPortID, int renterID, int ladyID, int purposeID, int rentInfoID) {
		// TODO Auto-generated method stub
		ladyDao.updateRPById(ladyID);
		rs.updateRpById(renterID);
		pls.updateCarPortIsRentById(carPortID);
		ps.updateIsDealById(purposeID);
		ps.delPurposeById(purposeID, rentInfoID);	
		rds.addRecord(purposeID);
	}

	@Override
	public Landlady findLandladyByLadyID(int ladyID) {
		// TODO Auto-generated method stub
		return ladyDao.findLandladyByLadyID(ladyID);
	}

	@Override
	public void deleteLandladyAndUserByLadyID(int ladyID) {
		// TODO Auto-generated method stub
		Landlady lady = ladyDao.findLandladyByLadyID(ladyID);
		System.out.println(lady.getPersonalcarport()+" "+lady.getLadyAddress());
		ladyDao.deleteLandladyAndUser(lady);
	}



}
